/**
 * 设定Cookie值
 * name, value, path, expires, domain, domain, secure
 */  
function setCookie(name, value, path, expires, domain, secure) {
	var expdate = new Date();
	if(expires!=null) {
		expdate.setTime(expdate.getTime() + ( expires * 1000 ));
	}
	/*
	document.cookie = name + "=" + escape (value) +( (expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
	+((path == null) ? ("; path=/") : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
	+((secure == true) ? "; secure" : "");
	*/
	var c = name + "=" + escape (value) ;
	c += (expires == null) ? "" : ("; expires="+ expdate.toGMTString());
	c += (path == null) ? ("; path=/") : ("; path=" + path);
	c += (domain == null) ? "" : ("; domain=" + domain);
	c += (secure == true) ? "; secure" : "";
	document.cookie = c;
}

/**
 * 设定Cookie值
 * name, value, path, expires, domain, domain, secure
 */
function saveCookie(name, value, path, expires, domain, secure){
	setCookie(name, value, path, expires, domain, secure);
}


/**
 * 删除cookie
 */
function deleteCookie(name, path, domain){
	setCookie(name, null, path, new Date(0), domain);
}

/**
 * 获得Cookie的原始值
 */
function getCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) {
		  var endstr = document.cookie.indexOf (";", j);
		  if (endstr == -1)
			endstr = document.cookie.length;
		  return document.cookie.substring(j, endstr);
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return "";
}
